package com.zygh.lz.service.impl;

import com.zygh.lz.dao.HierarchytypeMapper;
import com.zygh.lz.entity.Hierarchytype;
import com.zygh.lz.service.HierarchytypeService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HierarchytypeServiceImpl implements HierarchytypeService {
    @Resource
    private HierarchytypeMapper hierarchytypeMapper;


    @Override
    public List<Map> findHierarchytypeAll(Integer id) {
        return hierarchytypeMapper.findHierarchytypeAll(id);
    }

    @Override
    public ResultBean addHierarchytype(Hierarchytype hierarchytype) {
        Hierarchytype hierarchyEnd = hierarchytypeMapper.findHierarchyEnd(hierarchytype.getSptypeid());
        int hierarchyid = Integer.valueOf(hierarchyEnd.getHierarchyid());
        hierarchyid++;
        hierarchytype.setHierarchyid(String.valueOf(hierarchyid));
        return ResultUtil.setOK("success", hierarchytypeMapper.insertSelective(hierarchytype));
    }

    @Override
    public ResultBean deletHierarchytype(Integer id) {
        return ResultUtil.setOK("success", hierarchytypeMapper.deleteByPrimaryKey(id));
    }

    @Override
    public ResultBean updateHierarchytype(Hierarchytype hierarchytype) {
        return ResultUtil.setOK("success", hierarchytypeMapper.updateByPrimaryKeySelective(hierarchytype));
    }


}
